package cn.edu.sgu.www.mhxysy.controller.children_equipment;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.children_equipment.ChildrenEquipmentViewAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.children_equipment.ChildrenEquipmentViewAttribute;
import cn.edu.sgu.www.mhxysy.entity.except.Property;
import cn.edu.sgu.www.mhxysy.pager.children_equipment.ChildrenEquipmentViewAttributePager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.children_equipment.ChildrenEquipmentViewAttributeService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "子女装备预览属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/children_equipment_view_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChildrenEquipmentViewAttributeController {

	private final ChildrenEquipmentViewAttributeService chongwuEquipmentViewAttributeService;

	@Autowired
	public ChildrenEquipmentViewAttributeController(
			ChildrenEquipmentViewAttributeService chongwuEquipmentViewAttributeService) {
		this.chongwuEquipmentViewAttributeService = chongwuEquipmentViewAttributeService;
	}

	@ApiOperation("添加子女装备预览属性")
	@ApiOperationSupport(ignoreParameters = "id")
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	public JsonResult<Void> insert(@Validated ChildrenEquipmentViewAttributeDTO viewAttributeDTO) {
		chongwuEquipmentViewAttributeService.insert(viewAttributeDTO);

		return JsonResult.success(CustomMessages.INSERT_SUCCESS);
	}

	@ApiOperation("通过ID删除子女装备预览属性")
	@RequestMapping(value = "/deleteById", method = RequestMethod.POST)
	public JsonResult<Void> deleteById(
			@ApiParam(name = "id", value = "子女装备预览属性ID", required = true)
			@NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
		chongwuEquipmentViewAttributeService.deleteById(id);

		return JsonResult.success(CustomMessages.DELETE_SUCCESS);
	}

	@ApiOperation("通过ID修改子女装备预览属性")
	@RequestMapping(value = "/updateById", method = RequestMethod.POST)
	public JsonResult<Void> updateById(@Validated ChildrenEquipmentViewAttributeDTO viewAttributeDTO) {
		chongwuEquipmentViewAttributeService.updateById(viewAttributeDTO);

		return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
	}

	@ApiOperation("通过子女装备类型ID查询子女装备预览属性")
	@RequestMapping(value = "/selectByEquipmentId", method = RequestMethod.GET)
	public JsonResult<List<Property>> selectByEquipmentId(
			@ApiParam(name = "equipmentId", value = "子女装备类型ID", required = false)
			@RequestParam(required = false) Integer equipmentId) {
		List<Property> list = chongwuEquipmentViewAttributeService.selectByEquipmentId(equipmentId);

		return JsonResult.success(null, list);
	}

	@ApiOperation("分页查询子女装备预览属性列表")
	@RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
	public JsonResult<JsonPage<ChildrenEquipmentViewAttribute>> selectByPage(ChildrenEquipmentViewAttributePager pager) {
		Page<ChildrenEquipmentViewAttribute> page = chongwuEquipmentViewAttributeService.selectByPage(pager);

		return JsonResult.restPage(page);
	}

}